<?
include "../config/constants.php";

if( $_GET[_test] ){
	$_POST[CID] = TEST_CID;
}

if( !$_POST[CID] ){
	echo "ERROR: WRONG ARGUMENT";
	exit;
}

$cid = $_POST[CID];

$mysqli = mysqli_connect("localhost", "canss", "1022") or die("Could not connect: ".mysql_error());
mysqli_query($mysqli, "SET NAMES 'utf8'");


$query = "select	dc_creator, 
					dc_title,
					dc_format,
					xmpdm_copyright, 
					xmpdm_videoframesize, 
					canssvideo_audiocodecs, 
					canssvideo_videocodecs  
					FROM    `contentsmetadata_db`.`tblContent`
					WHERE   `tblContent`.`tblCID_cid`=\"$cid\"";

$result = mysqli_query($mysqli, $query);

if( !$result ){
	echo "ERROR : could not query";
	exit;
}

if( $r = mysqli_fetch_row($result) ){
	$arg = array(   "author",
					"title",
					"",
					"copyright",
					"s",
					"acodec",
					"vcodec" );

	// TODO: -_- 꼭 필요한가?
	$dev = array(   "unknown", 
					"untitle",
					"asf",
					"Canss",
					"qcif",
					"wm",
					"" );


	for( $i = 0 ; $i < sizeof($r) ; $i++ ){
		if( $r[$i] == "Default" || $r[$i] == "" ) $r[$i] = $dev[$i];
		if( $arg[$i] && $r[$i] ) $res = $res." -{$arg[$i]} \"{$r[$i]}\"";
	}
	$res = $res." ".MEDIA_CONTENT_PATH."/$cid.{$r[2]}";
	echo $res;
}
else{
	echo "ERROR : Content doesn't exist $cid";
	exit;
}

?>
